package Homework;

public class TestLinkedList {
    public static void main(String[] args) {
        //双向链表
        LinkedList linkedList = new LinkedList();
        linkedList.addFirst(11);
        linkedList.addFirst(22);
        linkedList.addFirst(33);
        linkedList.addLast(44);
        linkedList.addLast(55);
        System.out.println("初始链表：");
        linkedList.display();

        linkedList.addIndex(0,11);
        linkedList.display();
        linkedList.addIndex(linkedList.size(),11 );
        linkedList.display();

        System.out.println(linkedList.contains(44));
        System.out.println(linkedList.contains(23));
        linkedList.remove(11);
        linkedList.display();
        linkedList.removeAllKey(11);
        linkedList.display();
        linkedList.remove(55);
        linkedList.display();

        System.out.println(linkedList.size());
        linkedList.clear();
        System.out.println("清空后的链表：");
        linkedList.display();
    }
    public static void main1(String[] args) {
        //单向链表
        SingleLinkedList singleLinkedList = new SingleLinkedList();
        singleLinkedList.createList();
        System.out.println("初始的链表：");
        singleLinkedList.display();
        System.out.println();

        System.out.println("头插：");
        singleLinkedList.addFirst(84);
        singleLinkedList.display();
        System.out.println();

        System.out.println("尾插：");
        singleLinkedList.addLast(64);
        singleLinkedList.display();
        System.out.println();

        System.out.println("任意位置插入：");
        System.out.println( singleLinkedList.addIndex(3,99));
        singleLinkedList.display();
        System.out.println();

        System.out.println("查找是否包含关键字：");
        System.out.println(singleLinkedList.contains(99));
        System.out.println(singleLinkedList.contains(66));
        System.out.println();

        System.out.println("删除第一次出现的key：");
        singleLinkedList.remove(52);
        singleLinkedList.display();
        System.out.println();

        System.out.println("删除所有的key：");
        singleLinkedList.removeAllKey(52);
        singleLinkedList.display();
        System.out.println();

        System.out.println("目前链表长度：");
        System.out.println(singleLinkedList.size());
        System.out.println();

        System.out.println("清楚链表");
        singleLinkedList.clear();
        singleLinkedList.display();


    }
}
